package com.etime.shuhuiyuan.controllers.VideoUpload;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.Signature;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Random;

@Api(tags = "视频上传接口")
@RestController
@RequestMapping("/videoUpload")
public class VideoUploadController {

    @ApiOperation("获取签名案例")
    @GetMapping("/getSign")
    public BaseMessage getUploadSign(){
        BaseMessage msg = new BaseMessage();
        Signature sign = new Signature();
        // 设置 App 的云 API 密钥
        sign.setSecretId("AKID4wYuznKaaJkvpRmqeBRQ8ZjbDXaMr52i");
        sign.setSecretKey("QaKo2zf4B2ey1mHVR6VdU4MO9dplQouk");
        sign.setCurrentTime(System.currentTimeMillis() / 1000);
        sign.setRandom(new Random().nextInt(java.lang.Integer.MAX_VALUE));
        sign.setSignValidDuration(3600 * 24 * 2); // 签名有效期：2天

        try {
            String signature = sign.getUploadSignature();
            if (msg != null){
                msg.setMsg(signature);
                msg.setCode(1);
            }
            return msg;

        } catch (Exception e) {
            e.printStackTrace();
            // return JsonResult.fail("获取签名失败");
            msg.setCode(0);
            msg.setMsg("获取签名失败");
            return msg;
        }
    }
}
